home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Gfx / conv / GIFsplit.lha / source / GIFsplit.ab2 next >
Text File  |  2004-01-21  |  7KB  |  198 lines

  1.  
  2. ; GifSplit (Blitz) v1.0b GNU  Copyright (C) 2003-2004  Lorence Lombardo.
  3.  
  4. ; This program is Free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2 of the License, or
  7. ; (at your option) any later version.
  8.  
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY OR FITNESS For A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License For more details.
  13.  
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.  
  19. ; GifSplit (Blitz) was based on GifSplit.rexx by Bryan K. Williams
  20. ; which has been translated, optimized and re-written.
  21.  
  22. ; GIFsplit does not use any LZW patented algorithm.
  23.  
  24.  
  25. F$=Par$(1): l$=Chr$(10): np=NumPars: vb=0: dg=4: p3$=UCase$(Par$(3)): p4$=UCase$(Par$(4))
  26.  
  27. If np=0 OR F$="?" Then Goto usage
  28.  
  29. If np>2 AND p3$="V" Then vb=1
  30. If np>3 AND p4$="V" Then vb=1
  31. If np>2 AND Left$(p3$,1)="D" Then dg=Val(Mid$(p3$,2))
  32. If np>3 AND Left$(p4$,1)="D" Then dg=Val(Mid$(p4$,2))
  33.  
  34. fm$=String$("0",dg)
  35.  
  36.  
  37. If ReadFile(0,F$)
  38.  
  39.    ; Read GIF's dimensions.
  40.  
  41.    FileInput 0: hed$=Inkey$(6)
  42.    If hed$<>"GIF89a" AND hed$<>"GIF87a" Then NPrint l$,F$," file is not a GIF.",l$: End
  43.    gdim$=Inkey$(7)
  44.    width=c2d(StrFlip(Mid$(gdim$,1,2)))
  45.    height=c2d(StrFlip(Mid$(gdim$,3,2)))
  46.  
  47.  
  48.    stuff=c2d(Mid$(gdim$,5,1)): stuff$=Right$(Bin$(stuff),8)
  49.    GBC=Val(Left$(stuff$,1))
  50.    colres=Val("%"+Mid$(stuff$,2,3))+1
  51.    totalpal.l=(2^colres)^3
  52.    sortf=Val(Mid$(stuff$,5,1))         ; sort flag
  53.    SOT=Val("%"+Right$(stuff$,3))+1     ; size of table
  54.    backgrd = c2d(Mid$(gdim$,6,1))
  55.    ratio = c2d(Mid$(gdim$,7,1))
  56.    If ratio=0 Then ratio=1
  57.    hed$=hed$+gdim$
  58.  
  59.  
  60.    NPrint l$,"Screen Width     : ",width
  61.    NPrint "Screen Height    : ",height
  62.    If GBC NPrint "Global Color Map : Yes" Else NPrint "Global Color Map : No"
  63.    NPrint "Color Resolution : ",colres," bits (",totalpal," Total Palette)"
  64.    If sortf NPrint "Palette sorted by decreasing importance" Else NPrint "Palette unsorted"
  65.    NPrint "Bitplanes        : ",SOT," (",2^SOT," colors)"
  66.    NPrint "Background color : #",backgrd
  67.    NPrint "Pixel Ratio      : ",ratio,l$
  68.  
  69.  
  70.    ;read global color table (maybe)
  71.    ;3 bytes * 2^bitplates
  72.  
  73.  
  74.    gct$="": Format "000"
  75.    If GBC=1
  76.       If vb=1 Then NPrint "Reading global color table"
  77.       gct$=Inkey$(3*(2^SOT))
  78.       If vb=1
  79.          For x=1 To (2^SOT) Step 2
  80.             out$=" Color "+Str$(x)+" RGB "+Right$(c2x(Mid$(gct$,(x-1)*3+1,3)),6)
  81.             out$=out$+"  Color "+Str$(x+1)+" RGB "+Right$(c2x(Mid$(gct$,x*3+1,3)),6)
  82.             NPrint out$
  83.          Next x
  84.       EndIf
  85.    EndIf
  86.  
  87.  
  88.    ;Getting ready To split files.
  89.  
  90.    fcount.l=1: NPrint "": fstart$=Par$(2): If np<2 Then fstart$=""
  91.  
  92.  
  93.    While NOT Eof(0)
  94.       nx$=Inkey$: nx=Asc(nx$)
  95.       While nx<>$2C AND nx<>$3B
  96.          If nx=$21
  97.  
  98.             If vb=1 Then NPrint "Gif Extension code"
  99.  
  100.             bltype=Asc(Inkey$): lenn=c2d(Inkey$)
  101.  
  102.             If vb=1
  103.                Select bltype
  104.                   Case $F9: NPrint "Graphic Control Extension"
  105.                   Case $FE: NPrint "Comment Extension"
  106.                   Case $01: NPrint "Play Text Extension"
  107.                   Case $FF: NPrint "Application Extension"
  108.                   Default : NPrint "Unknown Extension of hex type ",Right$(Hex$(bltype),2)
  109.                End Select
  110.                NPrint ""
  111.             EndIf
  112.  
  113.             bla$=Inkey$(lenn) ; Application Extension Type
  114.             If bltype=$FF
  115.                BlkLen = c2d(Inkey$) ; Read Length of extension Type
  116.                bla$=Inkey$(BlkLen) ; Read Application Extension Data
  117.             EndIf
  118.             ending=Asc(Inkey$)
  119.             If ending<>0 Then NPrint "No data terminator for this block, exiting...",l$: End
  120.  
  121.          Else
  122.             NPrint "Somethings wrong. Hex character ",c2x(nx$)," found.  Exiting...",l$
  123.             End
  124.          EndIf
  125.          nx$=Inkey$: nx=Asc(nx$)
  126.       Wend
  127.       If nx=$3B Then NPrint "File termination found, exiting...",l$: CloseFile 0: End
  128.       Format fm$: NPrint Chr$(11)+"Found image number ",fcount: Format ""
  129.  
  130.       codehed$ = nx$+Inkey$(9)
  131.  
  132.       imageleft = c2d(StrFlip(Mid$(codehed$,2,2)))
  133.       imagetop = c2d(StrFlip(Mid$(codehed$,4,2)))
  134.       imagewidth = c2d(StrFlip(Mid$(codehed$,6,2)))
  135.       imageheight = c2d(StrFlip(Mid$(codehed$,8,2)))
  136.       stuff = c2d(Right$(codehed$,1)): stuff$=Right$(Bin$(stuff),8)
  137.       localcolor = Val(Left$(stuff$,1))
  138.       interlace = Val(Mid$(stuff$,2,1))
  139.       localsortflag = Val(Mid$(stuff$,3,1))
  140.       localcolortable = Val("%"+Right$(stuff$,3))+1
  141.  
  142.       If vb=1
  143.          NPrint "Image Left  : ",imageleft
  144.          NPrint "Image Top   : ",imagetop
  145.          NPrint "Image Width : ",imagewidth
  146.          NPrint "Image Height: ",imageheight
  147.          If localcolor NPrint "Local Color Table : Yes" Else NPrint "Local Color Table : No"
  148.          If interlace NPrint "Interlaced" Else NPrint "Not Interlaced"
  149.          If localSortflag NPrint "Palette sorted by decreasing importance" Else NPrint "Palette unsorted"
  150.       EndIf
  151.  
  152.       lct$="": Format "000"
  153.       If localcolor=1
  154.          If vb=1 Then NPrint "Reading local color table"
  155.          lct$=Inkey$(3*(2^localcolortable))
  156.          If vb=1
  157.             For x = 1 To (2^localcolortable) Step 2
  158.                out$=" Color "+Str$(x)+" RGB "+Right$(c2x(Mid$(lct$,(x-1)*3+1,3)),6)
  159.                out$=out$+"  Color "+Str$(x+1)+" RGB "+Right$(c2x(Mid$(lct$,x*3+1,3)),6)
  160.                NPrint out$
  161.             Next x
  162.          EndIf
  163.       EndIf
  164.  
  165.       code$=Inkey$: codesize$=Inkey$
  166.       code$=code$+codesize$: chsz = c2d(codesize$)
  167.  
  168.       Format fm$: fout$=fstart$+Str$(fcount)
  169.  
  170.       If WriteFile (1,fout$)
  171.          FileOutput 1: Print hed$+gct$+codehed$+lct$
  172.          While chsz>0 AND NOT Eof(0)
  173.             code$=code$+Inkey$(chsz): Print code$
  174.             code$=Inkey$: chsz = c2d(code$)
  175.          Wend
  176.          Print code$: DefaultOutput: CloseFile 1
  177.          If vb=1 Then NPrint "End of image.",l$
  178.       Else
  179.          NPrint l$,"Could not output files.",l$: End
  180.       EndIf
  181.  
  182.       fcount+1
  183.  
  184.    Wend
  185. Else
  186.    NPrint l$,F$," file not found.",l$: End
  187. EndIf
  188.  
  189. NPrint l$,"??? Premature EOF ???",l$: CloseFile 0: End
  190.  
  191.  
  192. usage:
  193. NPrint l$," GifSplit (Blitz) v1.0b GNU  (C) 2003-2004  Lorence Lombardo.",l$
  194. NPrint " Usage:- GifSplit infile outfile [V=VERBOSE] [D#=DIGIT#]"
  195. NPrint "         eg. GifSplit GifAnim.GIF Pic. D6",l$
  196. End
  197.  
  198.